﻿using System;
using System.Windows;
using Columbus;
using Ninject;
using Ninject.Modules;

namespace ColumbusWithNinjectSample
{
    public class ApplicationModule : NinjectModule
    {
        public override void Load()
        {
            // Views
            Bind<FrameworkElement>().To<Page1>().InTransientScope().Named("Page1");
            Bind<FrameworkElement>().To<Page2>().InTransientScope().Named("Page2");

            // Controllers
            Bind<Controller>().To<ApplicationController>().InSingletonScope().Named("ApplicationController");

            // Navigation
            Bind<Func<string, Controller>>().ToConstant(x => Kernel.Get<Controller>(x)).InSingletonScope();
            Bind<Func<string, FrameworkElement>>().ToConstant(x => Kernel.Get<FrameworkElement>(x)).InSingletonScope();
            Bind<ITransientStore>().To<TransientStore>().InSingletonScope();
            Bind<NavigationAppication>().ToSelf().InSingletonScope()
                .WithConstructorArgument("defaultAction", new Action<INavigator>(n => n.NavigateTo<ApplicationController>(c => c.Page1())));
            Bind<INavigator>().To<Navigator>().InSingletonScope()
                .WithConstructorArgument("frameName", Navigator.DefaultNavigationFrameName);
        }
    }
}